<template>
  <div class="login-setting">
    <el-form ref="form" :rules="rules" :model="userInfo" label-width="120px">
      <el-form-item label="姓名" prop="username">
        <el-input v-model="userInfo.username" style="width:300px" />
      </el-form-item>
      <el-form-item label="密码" prop="password">
        <el-input v-model="userInfo.password" type="password" style="width:300px" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="hSave">更新</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { saveUserDetailById } from '@/api/employees.js'
import { getUserDetailById } from '@/api/user.js'
export default {
  data() {
    return {
      userInfo: {
        username: '',
        password: ''
      },
      rules: {
        username: [{ required: true, message: '用户名不能为空', triggler: 'blur' }],
        password: [{ required: true, message: '密码不能为空', triggler: 'blur' }]
      }
    }
  },
  created() {
    this.loadUserDetailById()
  },
  methods: {
    // 获取姓名和密码
    async loadUserDetailById() {
      const res = await getUserDetailById(this.$route.query.id)
      console.log(res)
      // const { username, password } = res.data
      this.userInfo = res.data
    },
    hSave() {
      this.$refs.form.validate(async(valie) => {
        if (valie) {
          await saveUserDetailById(this.userInfo)
          this.$message.success('修改成功')
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
